#!/usr/bin/env bash

if [ -e /cm4gitlab-runner-maven/settings.xml ]
then
  which mvn
  cp -rLHvf /cm4gitlab-runner-maven/. "$(which mvn|sed -E 's#/bin/mvn$##g')/conf/"
fi

if [ -e /secret4gitlab-runner-docker/config.json ]
then
  mkdir -p "$HOME/.docker/"
  cp -rLHvf /secret4gitlab-runner-docker/. "$HOME/.docker/"
fi

if [ -e /secret4gitlab-runner-kube/config ]
then
  mkdir -p "$HOME/.kube/"
  cp -rLHvf /secret4gitlab-runner-kube/. "$HOME/.kube/"
  chmod 600 "$HOME/.kube/config"
fi

if [ -e /cm4gitlab-runner-home/.itohrc ]
then
  cp -rLHvf /cm4gitlab-runner-home/. $HOME/
fi

helm3 repo add x "${CI_HELM_CHART}"

cat <<EOF >> git.properties
git.branch=${CI_COMMIT_BRANCH}
git.build.host=${CI_SERVER_NAME}
git.build.time=${CI_JOB_STARTED_AT}
git.build.user.name=${GITLAB_USER_NAME}
git.build.user.email=${GITLAB_USER_EMAIL}
git.build.version=${CI_JOB_ID}
git.closest.tag.commit.count=
git.closest.tag.name=${CI_COMMIT_REF_NAME}
git.commit.author.time=${CI_COMMIT_TIMESTAMP}
git.commit.committer.time=${CI_COMMIT_TIMESTAMP}
git.commit.id=${CI_COMMIT_SHA}
git.commit.id.abbrev=${CI_COMMIT_SHORT_SHA}
git.commit.id.describe=
git.commit.id.describe-short=
git.commit.message.full=${CI_COMMIT_MESSAGE//\n/\\n}
git.commit.message.short=${CI_COMMIT_TITLE}
git.commit.time=${CI_COMMIT_TIMESTAMP}
git.commit.user.email=
git.commit.user.name=${CI_COMMIT_AUTHOR}
git.dirty=
git.local.branch.ahead=
git.local.branch.behind=
git.remote.origin.url=${CI_PROJECT_URL}
git.tags=${CI_COMMIT_TAG}
git.total.commit.count=
EOF
